//
//  assetsOrderComViewController.m
//  DBAChain
//
//  Created by Mxionlly on 2018/9/7.
//  Copyright © 2018年 Evan. All rights reserved.
//

#import "assetsOrderComViewController.h"
#import "OrderQiuGouTableViewCell.h"
#import "CommonData.h"
#import "JiaoYiPageDetailViewController.h"
#import "dataOrderBuyAndSaleInfo.h"
#import "taskOverviewService.h"
#import "AssetsOrderingTableViewCell.h"

@interface assetsOrderComViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong)    UITableView *tableViewAppeal;
@property (nonatomic,assign)NSInteger      page;
@property (nonatomic,strong)    NSMutableArray<dataOrderBuyAndSaleInfo *> *  orderList;
@end

@implementation assetsOrderComViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self hideHeadView];
    self.orderList = [[NSMutableArray<dataOrderBuyAndSaleInfo *> alloc]init];
    [self.view addSubview:self.tableViewAppeal];
    self.tableViewAppeal.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        [self loadDataAppeal];
    }];
    self.tableViewAppeal.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        [self loadMoreData];
    }];
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    self.hidesBottomBarWhenPushed = NO;
    self.tabBarController.tabBar.hidden = YES;
    self.navigationController.navigationBar.hidden = NO;
    [self setBlackStatus:YES];
    [self loadDataAppeal];
}

-(void)loadDataAppeal{
    self.page = 1;
    [self loadOrder:1];
}

-(void)loadMoreData{
    self.page ++;
    [self loadOrder:self.page];
}

-(void)loadOrder:(NSInteger) pageIndex{
    NSMutableDictionary *dict = [NSMutableDictionary new];
    [dict setField:[NSString stringWithFormat:@"%ld",self.page] value:@"pageindex"];
    [dict setField:@"10" value:@"pagesize"];
    [dict setField:@"1" value:@"ordertype"];//交易类型：1 求购 0 出售
    [dict setValue:@(3) forKey:@"orderStatus"];//订单状态：0：等待交易，1：交易中 2：交易完成 3：申诉
    [dict setValue:@(1) forKey:@"isAll"];//是否查询所有：0：所有交易订单，1：个人交易订单
    [taskOverviewService getOrderBuyAndSaleList:dict success:^(dataOrderBuyAndSale *response, BOOL success) {
        [DKProgressHUD dismiss];
        [self.tableViewAppeal.mj_footer endRefreshing];
        [self.tableViewAppeal.mj_header endRefreshing];
        if (success) {
            if (pageIndex == 1) {
                self.orderList  = response.data;
            }else{
                [self.orderList addObjectsFromArray:response.data];
            }
            [self.tableViewAppeal reloadData];
            return ;
        }else{
            [DKProgressHUD showErrorWithStatus:response.message];
        }
    } failture:^(NSError *error, NSString *strDescription) {
        [DKProgressHUD dismiss];
        [DKProgressHUD showErrorWithStatus:strDescription];
    }];
}

#pragma mark - tableview

-(UITableView *)tableViewAppeal
{
    if (!_tableViewAppeal) {
        _tableViewAppeal = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight-64) style:UITableViewStyleGrouped];
        _tableViewAppeal.dataSource = self;
        _tableViewAppeal.delegate = self;
        _tableViewAppeal.backgroundColor  = [UIColor clearColor];
        _tableViewAppeal.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
        [_tableViewAppeal registerClass:[AssetsOrderingTableViewCell class] forCellReuseIdentifier:@"AssetsOrderingTableViewCell"];
    }
    return _tableViewAppeal;
}



-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.orderList count];
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 74;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    OrderQiuGouTableViewCell *cell = [OrderQiuGouTableViewCell cellWithTableView:tableView IndexPath:indexPath];
    dataOrderBuyAndSaleInfo *m =  [self.orderList objectAtIndex:indexPath.row];
    dataOrderBuyAndSaleInfo *mm = [dataOrderBuyAndSaleInfo mj_objectWithKeyValues:m];
    cell.labelCNY.text = [NSString stringWithFormat:@"%@ CNY",mm.PriceCountRMB];
    cell.labelName.text = [NSString stringWithFormat:@"订单编码：%ld",(long)mm.ID];
    cell.labelTime.text = [NSString stringWithFormat:@"%@     ",mm.CreateTimeName];
    cell.labelPrice.text = [NSString stringWithFormat:@"单价：%@CNY",mm.PriceRMB];
    cell.lbnum.text = [NSString stringWithFormat:@"数量：%@ china-A",mm.ChinaANumber];
    cell.lblimit.text = mm.TransactionStatusName;//[NSString stringWithFormat:@"限额：%@-%@ ",mm.LimitMix,mm.LimitMax];

    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
//    dataOrderBuyAndSaleInfo *m =  [self.orderList objectAtIndex:indexPath.row];
//    dataOrderBuyAndSaleInfo *mm = [dataOrderBuyAndSaleInfo mj_objectWithKeyValues:m];
//
//    JiaoYiPageDetailViewController *vc =[JiaoYiPageDetailViewController new];
//    vc.orderId =mm.ID;
//    [self.navigationController pushViewController:vc animated:YES];
    
}
/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */


@end
